home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
105_01
/
long.doc
< prev
next >
Wrap
Text File
|
1984-06-03
|
4KB
|
109 lines
LONG INTEGERS
(c) 1981 by Paul J. Gans
The Long Integer Package
The Long Integer Package is a collection of functions
designed to provide the users of Leor Zolman's BDS C with
the ability to manipulate long integers. This package has
been modeled upon the Floating Point Package for BDS C
written by Bob Mathias and works in a similar manner.
The package works with long integers stored as four
consecutive bytes with the least significant byte stored
at the lowest memory address. The precision maintained is
31 bits plus sign. To use the package, all long integers
should be declared as four byte char arrays. Manipulation
is by pointer to the arrays. Thus the code
char first[4], second[4], result[4];
could define three long integers.
The possible range a long integer longform may
occupy is:
-2147483648 <= longform <= 2147483647
Long integers are manipulated via the following
functions:
char *ladd(sum,addend,augend)
char sum[4], addend[4], augend[4];
adds addend and augend, stores the 32 bit signed
result in sum and returns a pointer to sum.
char *lsub(diff,minuend,subtrahend)
char diff[4], minuend[4], subtrahend[4];
subtracts subtrahend from minuend and places the
32 bit signed result in diff. A pointer to diff
is returned.
char *lmul(prod,plier,plicand)
char prod[4], plier[4], plicand[4];
plier and plicand are multiplied. The least
signficant 31 bits of the product along with the
appropriate sign bit are stored in prod. A pointer
to prod is returned.
char *ldiv(quot,dividend,divisior)
char quot[4], dividend[4], divisor[4];
dividend is divided by divisor. The least
significant 31 bits of the quotient along with the
proper sign are stored in quot. A pointer to prod
is produced. Note that no indication of overflow
is produced should it occur.
char *lmod(res,dividend,divisor)
char res[4], dividend[4], divisor[4];
dividend is divided by divisor. The positive 31
bit remainder is placed in res and a pointer to it
is returned.
char *lneg(newnum,orignum)
char newnum[4], orignum[4];
orignum is negated and placed in newnum. A pointer
to newnum is returned.
char *itol(longform,i)
char longform[4];
int i;
i is converted to long integer form and placed in
longform to which a pointer is returned.
int ltoi(i,longform)
char longform[4];
int i;
the low order 15 bits of longform along with the
proper sign are placed in i, which value is returned.
char *atol(longform,s)
char longform[4], *s;
the '\0' terminated ASCII string s is converted to
a long integer and stored in longform to which a
pointer is returned. The proper format for s is:
any amount of white space followed by an optional
sign followed by decimal digits. The first non-
digit terminates the scan. No check is made for
overflow and improper results will result if too
many decimal digits are presented.
char *ltoa(s,longform)
char longform[4], *s;
the long integer longform is converted to a '\0'
terminated ASCII string prefixed by a minus sign
if longform is negative. The string is placed in
s to which a pointer is returned. Note that the
maximum length s may attain is 12, counting 10
numerical digits, a possible minus sign, and the
terminating '\0'.
The Long Integer Package was written by Paul J. Gans,
Department of Chemistry, New York University, New York,
NY 10003. Phone (212) 598-2515. Bug reports welcomed.
d retu